package com.gaoxinfu.demo.mongodb;

import org.springframework.data.mongodb.core.MongoOperations;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @Description:
 * @Author: gaoxinfu
 * @Date: 2020-10-22 16:36
 */
@RestController
public class HelloController {

    @Resource
    private MongoOperations mongoOperations;

    @RequestMapping(value = "hello/{name}",method = RequestMethod.GET)
    public String hello(@PathVariable String name){

        Person person=new Person("1",name,18,"man");
        return "HelloController.hello ="+name;
    }

    @RequestMapping(value = "hello/add",method = RequestMethod.GET)
    public String addPerson(){
        Person person=new Person("1","gaoxinfu",18,"man");
//        return "HelloController.hello ="+name;
        mongoOperations.save(person);
        return "保存成功";
    }
}
